<%-- 
    Document   : Home
    Created on : Apr 2, 2012, 8:54:57 AM
    Author     : Y.Yang
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*" 
        import="java.io.IOException"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>UAlbanyBook</title>
        <link rel="stylesheet" type="text/css" href="default.css" />
    </head>
    <body>
    <div id="header">
    <div id="slogan">
    UAlbanyBook
    </div>
    <div>
      
      <a id = "headerlink" href="Home.jsp"> Home</a>
      <a id = "headerlink" href="Profile.jsp">My Profile</a>
      <a id="w"><% if(session.getAttribute("user")== null){
                        response.sendRedirect("Home.jsp");
                    }
                    else
                       out.println("Welcome " +session.getAttribute("user")+"!");%></a>
      <a id = "headerlink" href="index.jsp">Sign out</a>
    </div>
    <div id = "searcharea">
     
      <form name="form2" method="post" action="">
       
      
      <label for="Searchbar"></label><input type="text" name="searchFirstName" id="Search" size="50">
       
      <input type="submit" name="search" id="search" value="Search">
      <p>
      </p>
      <table width="697" border="2">
        <tr>
          <th width="436" height="44" scope="col">&nbsp;</th>
        
        </tr>
        <%
        String URL = "jdbc:mysql://localhost:3306/ualbanybook";
        String USERNAME = "root";
        String PASSWORD = "isaac16";
        Connection connection = null;
        PreparedStatement statement = null;
        PreparedStatement statement1 = null;
         PreparedStatement statement2 = null;
        ResultSet rstLogin = null;
        ResultSet rstfriend = null;
        
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            String searchFirstName = request.getParameter("searchFirstName");
            statement = connection.prepareStatement("SELECT * FROM useraccount WHERE firstName=?");
            statement.setString(1, searchFirstName);
			
            rstLogin = statement.executeQuery();
            while(rstLogin.next())
            {%>
            
         <form name="form1" method="post" action="SendFriendRequest">
         <tr>
          <td><p>
          <input type="text" id = "headerlink2" name = "sendFriendReqTo" value="<%out.println(rstLogin.getString("Email"));%>">
           <input type="submit" name="sendFriendRequest" id="search" value="sendFriendRequest">
           </form>
           
          
          </a></p>
          <p>&nbsp;</p></td>
        </tr>
        
          
           
            <%}%>
      </table>
      </form>
        <%
               }
        catch(ClassNotFoundException e){
        out.println("Couldn't load database driver: " + e.getMessage());
        }
        catch (SQLException sqlException){
            out.println(sqlException.getMessage());
            
        }  
        finally {            
            try{
                if(connection != null)
                    connection.close();
                if(rstLogin != null)
                    rstLogin.close();
            }
            catch(SQLException ignored){
            out.println(ignored.getMessage()); 
            }
        }
        %>
        
       
    <p>&nbsp;<label></label></p>
    </div>
  
    </body>
</html>
